from django.db import models
from django.db.models import signals
from .signals import update_twitter
import datetime

class Tweet(models.Model):
    twitter_id = models.PositiveIntegerField(blank=True, editable=False)
    created_at = models.DateTimeField(default=datetime.datetime.now, editable=False)
    content = models.CharField(max_length=160)
    source = models.CharField(max_length=100, editable=False)
    truncated = models.BooleanField(default=False, editable=False)
    
    def __unicode__(self):
        return self.content[:50]
    
    def get_absolute_url(self):
        return 'http://twitter.com/twittuga/statuses/%d' % self.twitter_id
    
    class Meta:
        ordering = ('-twitter_id',)
signals.pre_save.connect(update_twitter, Tweet)